<html>
<head><meta charset="utf-8"><title>llvm codegen doesnt dispose of module · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html">llvm codegen doesnt dispose of module</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244045525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244045525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244045525">(Jun 27 2021 at 02:23)</a>:</h4>
<p>Im working on a codegen that depends on the existing llvm codegen for some parts, and it seems that for some reason it does not dispose of llvm modules by calling <code>LLVMDisposeModule</code>, it does dispose of the context however. Is this intentional? i cant do it in my backend because <code>LLVMModuleCreateWithNameInContext</code> returns an immutable reference and im pretty certain turning that into a mutable ptr then giving it to llvm to nuke is violating reference rules.</p>



<a name="244045648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244045648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244045648">(Jun 27 2021 at 02:27)</a>:</h4>
<p>although the module is just an opaque type so it would <em>probably</em> be fine? i dont want to get my hands cut off by ferris for violating stacked borrows</p>



<a name="244045704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244045704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244045704">(Jun 27 2021 at 02:29)</a>:</h4>
<p>modifying through <code>&amp;T</code> is always UB</p>



<a name="244045705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244045705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244045705">(Jun 27 2021 at 02:29)</a>:</h4>
<p>even if it's through a raw pointer derived from the reference</p>



<a name="244045752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244045752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244045752">(Jun 27 2021 at 02:30)</a>:</h4>
<p>right which is why i dont think im allowed to dispose of it right now, unless i manually declare the context creation function and modify it to return a ptr</p>



<a name="244049632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244049632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244049632">(Jun 27 2021 at 04:47)</a>:</h4>
<p>I don't know if this helps, but <code>LLVMModuleCreateWithNameInContext</code> adds the module to the context, and disposing of the context with <code>LLVMContextDispose</code> deletes the modules that were added to it. That wasn't immediately obvious to me when I was looking in this area.</p>
<p>The design of these FFI functions with respect to reference types they accept and return seemed off to me, but I never dug into it. Check out <a href="https://github.com/rust-lang/rust/issues/52461">#52461</a> if you want to look deeper into that.</p>



<a name="244050166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244050166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244050166">(Jun 27 2021 at 05:04)</a>:</h4>
<p>ohh i see, that makes sense</p>



<a name="244050251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244050251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244050251">(Jun 27 2021 at 05:07)</a>:</h4>
<p>using references doesnt really make sense to me because everything expects opaque pointers anyways and there isnt anything you can do on the objects</p>



<a name="244050302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20codegen%20doesnt%20dispose%20of%20module/near/244050302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20codegen.20doesnt.20dispose.20of.20module.html#244050302">(Jun 27 2021 at 05:09)</a>:</h4>
<p>it does make it easier to annotate what things can be written to or not though</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>